package com.sams.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sams.entity.Baseinfo;
import com.sams.entity.BaseinfoExample;
import com.sams.entity.BaseinfoExample.Criteria;
import com.sams.mapper.BaseinfoMapper;
import com.sams.service.BaseInfoService;
@Service
public class BaseInfoServiceImpl implements BaseInfoService{
	
	@Autowired
	private BaseinfoMapper mapper;
	
	public List<Baseinfo> listAll(Integer pid) {
		BaseinfoExample example = new BaseinfoExample();
		Criteria criteria = example.createCriteria();
		if(pid!=null) {
			criteria.andpIdEqualTo(pid);
		}
		 
		return mapper.selectByExample(example);
	}

	public int delete(Integer id) {
 		return mapper.deleteByPrimaryKey(id);
	}

	public List<Baseinfo> getNameByType(Integer typeid) {
		BaseinfoExample example = new BaseinfoExample();
		Criteria criteria = example.createCriteria();
	 
			criteria.andTypeEqualTo(typeid);
	 
		return mapper.selectByExample(example);
	}

	public int add(Baseinfo baseinfo) {
		// TODO Auto-generated method stub
		if(baseinfo.getId()==null) {
			return mapper.insert(baseinfo);
		}else {
			return mapper.updateByPrimaryKey(baseinfo);
		}
		
	}
	/**
	 * 查询所有的子节点  （子节点 全部是学校）
	 * @return
	 */
	public List<Baseinfo> selectAllChild(){
		
		return mapper.selectAllChild();
	}
	/**
	 * 根据id 查询一个对象集合
	 */
	public List<Baseinfo> findById(Integer id) {
		BaseinfoExample example = new BaseinfoExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(id);
		
		return mapper.selectByExample(example);
	}
 

}
